<?php
/**
 * Class C_OrderList 客户端 订单列表
 */
namespace V5;
class  C_OrderList extends \V4\C_OrderList{

    public $isActive = true;
    public $remark = '获取客户端订单列表';

    public function get(array $req, array $post, &$result){
        try {
            /* 授权验证【开始】 */
            if (!isset($req['uid'])) {
                return 'require user id ';
            }
            if (!isset($req['userType'])) {
                return 'require user type';
            }
            if (!isset($req['k']) || !isset($req['t'])) {
                return 'data error';
            }
            $customer_handler = new \Biz\UserHandler();
            $customer_cls = $customer_handler ->getById($req['userType'],$req['uid']);
            if(!is_object($customer_cls) && $customer_cls->getEnterpriseId() ==false){
                return 'data error';
            }
            $enterprise_id = $customer_cls ->getEnterpriseId();
            if (\Biz\UserHandler::checkAuth($req['userType'],$req['uid'],$enterprise_id,$req['t'],$req['k']) == false) {
                return 'data illegal';
            }
            /* 授权验证【结束】 */
            if(!array_key_exists('uid',$req)||empty($req['uid'])){
                return 'require uid';//买家id
            }
            if(!array_key_exists('channelId',$req)||empty($req['channelId'])){
                return 'require channelId';//渠道id
            }
            $l = isset($req['l']) ? $req['l'] : 100000;
            $o = isset($req['o']) ? $req['o'] : 0;
            // 实例化列表类
            $tabulation = new \Cls\Tabulation();
            // 初始化列表类相关参数
            if(array_key_exists('ordercode',$req)&&!empty($req['ordercode'])){
                $tabulation->setWhere('ordercode', $req['ordercode']);
            }
            $tabulation->setWhere('enterprise_customer_id', $req['uid'])
                ->setWhere('enterprise_channel_id', $req['channelId'])
                ->setWhere('enterprise_id', $enterprise_id)
                ->setWhere('status', '>','0')
                ->setOffset($o)
                ->setLimit($l)
                ->setOrderBy('id', 'desc');
            $order_handler = new \Biz\OrderHandler();
            $order_handler->getOrderListByEnterpriseAndCustomerAndChannel($tabulation);
            $order_info = array();
            if($tabulation->getSuccessStatus()){
                foreach($tabulation->getData() as $order_cls){
                    $order_tmp = array();
                    $order_tmp['id'] = $order_cls->getId();
                    $order_tmp['ordercode'] = $order_cls->getCode();
                    $order_tmp['enterprise_id'] = $order_cls->getEnterpriseId();
                    $order_tmp['enterprise_customer_id'] = $order_cls->getEnterpriseCustomerId();
                    $order_tmp['enterprise_channel_id'] = $order_cls->getEnterPriseChannelId();
                    $order_tmp['status'] = $order_cls->getStatus();
                    $order_tmp['contact'] = $order_cls->getContact();
                    $order_tmp['tel'] = $order_cls->getTelephone();
                    $order_tmp['price'] = $order_cls->getPrice();
                    $order_tmp['discount'] = $order_cls->getDiscount();
                    $order_tmp['coupon'] = $order_cls->getConupon();
                    $order_tmp['need_pay_price'] = $order_cls->getNeedPayPrice();
                    $order_tmp['pay_status'] = $order_cls->getPayStatus();
                    $order_tmp['pay_datetime'] = $order_cls->getPayTime();
                    $order_tmp['pay_message'] = $order_cls->getPayMessage();
                    $order_tmp['delivery_status'] = $order_cls->getDeliveryStatus();
                    $order_tmp['delivery_charge'] = $order_cls->getDeliveryCharge();
                    $order_tmp['delivery_time'] = $order_cls->getDeliveryTime();
                    $order_tmp['delivery_province_id'] = $order_cls->getDeliveryProvinceId();
                    $order_tmp['delivery_city_id'] = $order_cls->getDeliveryCityId();
                    $order_tmp['delivery_address'] = $order_cls->getDeliveryAddress();
                    $order_tmp['remark'] = $order_cls->getRemark();
                    $order_tmp['active_discount'] = $order_cls->getActiveDiscount();
                    $order_tmp['insert_time'] = $order_cls->getInsertTime();
                    $order_tmp['update_time'] = $order_cls->getUpdateTime();
                    $order_tmp['is_pay_type'] = $order_cls->getIsPayType();
                    $order_tmp['pay_type_item_id'] = $order_cls->getPayTypeItemId();
                    $order_tmp['transaction_id'] = $order_cls->getTransactionId();
                    $order_tmp['status_string'] = $order_cls->getStatusStr();
                    $order_tmp['pay_status_string'] = $order_cls->getPayStatusStr();
                    $order_tmp['delivery_status_string'] = $order_cls->getDeliveryStatusStr();
                    $order_tmp['company'] = $order_cls->getEnterpriseCustomerInfo()->getCompany();
                    $order_info['lists'][] = $order_tmp;
                }
            }
            $total = $tabulation->getTotal();
            $order_info['total'] = $total;
            $result = $order_info;
        } catch (Exception $e) {
            return $e->getMessage();
        }

    }
}
?>